#include "stdafx.h"
#include "ExpansionBus.h"


ExpansionBus::ExpansionBus(ChipBus& recordQueue, sqlite3x::connection& connection)
	:m_recordQueue(recordQueue),m_memory(connection)
{

}

ExpansionBus::~ExpansionBus()
{
}

void ExpansionBus::Run()
{
	bool quitFlag = false;
	while (!quitFlag)
	{
		ChipMessage const& message = m_recordQueue.Pop(quitFlag);
		if (quitFlag)
			break;

		MemoryNotification const& notification = *(MemoryNotification*)message.data;
		switch (message.type)
		{
		case ChipMessage::MEMORY_SAVE:
			{
				OnSave(notification);
			}
			break;
		case ChipMessage::MEMORY_LOAD:
			{
				OnLoad(notification);
			}
			break;
		default:
			break;
		}
	}
}

struct ClientInfo;
void ExpansionBus::OnSave(MemoryNotification const& notification)
{
	m_memory.Save(notification.type, notification.data, notification.sql);
}

void ExpansionBus::OnLoad(MemoryNotification const& notification)
{
}
